package com.lkd.controller;

import com.lkd.dto.RegionDto;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.service.RegionService;
import com.lkd.vo.RegionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service")
public class RegionController {

    @Autowired
    private RegionService regionService;

    /**
     * 分页查询 区域管理
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/region/search")
    public Result<PageBean<RegionVo>> findByRegionPage(
            @RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "name", required = false) String name
    ) {
        PageBean<RegionVo> pageBean = regionService.findByRegionPage(pageIndex, pageSize, name);
        return Result.success(pageBean);
    }

    /**
     * 新增区域
     * @param dto
     * @return
     */
    @PostMapping("/region")
    public Result save(@RequestBody RegionDto dto){
        regionService.save(dto);
        return Result.success();
    }

    /**
     * 修改区域
     * @param dto
     * @return
     */
    @PutMapping("/region")
    public Result update(@RequestBody RegionDto dto){
        regionService.update(dto);
        return Result.success();
    }
}
